package com.tju.ocean_ecology_website.controller;

import com.tju.ocean_ecology_website.dto.ApiResponse;
import com.tju.ocean_ecology_website.service.VolunteerServiceRecordService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;

import javax.annotation.Resource;

/**
 * 志愿者服务时长管理控制器（管理员使用）
 */
@RestController
@RequestMapping("/admin/volunteer")
public class VolunteerServiceHoursAdminController {

    @Resource
    private VolunteerServiceRecordService volunteerServiceRecordService;

    /**
     * 手动触发更新所有志愿者的服务时长统计
     *
     * @return 操作结果
     */
    @PostMapping("/hours/update-all")
    public ResponseEntity<ApiResponse<String>> updateAllVolunteerHours() {
        volunteerServiceRecordService.scheduledUpdateAllVolunteerTotalHours();
        return ResponseEntity.ok(ApiResponse.success("已触发所有志愿者服务时长统计更新"));
    }

    /**
     * 手动触发更新指定志愿者的服务时长统计
     *
     * @param volunteerId 志愿者ID
     * @return 操作结果
     */
    @PostMapping("/hours/update/{volunteerId}")
    public ResponseEntity<ApiResponse<String>> updateVolunteerHours(@PathVariable Long volunteerId) {
        volunteerServiceRecordService.updateVolunteerTotalHours(volunteerId);
        return ResponseEntity.ok(ApiResponse.success("已更新志愿者ID为" + volunteerId + "的服务时长统计"));
    }
}
